<template>
  <div>
<!--  :data=""  -->
    <el-table bordera  style="width: 100%" :data="skuList">
      <el-table-column type="index" label="序号" width="180" align="center"></el-table-column>
      <el-table-column prop="skuName" label="名称" width="width"></el-table-column>
      <el-table-column prop="skuDesc" label="描述" width="width"></el-table-column>
      <el-table-column prop="prop" label="默认图片" width="width">
        <template slot-scope="{row,$index}" class="demo-image__preview">
          <el-image :src="row.skuDefaultImg"
                    :preview-src-list="[row.skuDefaultImg]"
                    style="height:100px;weight:100px">
          </el-image>
<!--          <img :src="row.skuDefaultImg" style="height:100px;weight:100px">-->
        </template>
      </el-table-column>
      <el-table-column prop="weight" label="重量" width="width"></el-table-column>
      <el-table-column prop="price" label="价格" width="width"></el-table-column>
      <el-table-column prop="date" label="操作" width="300px" align="center">
        <template slot-scope="{row,$index}">
          <el-button type="success" icon="el-icon-top" size="mini" title='商品上架' v-if="row.isSale==0" @click="onSale(row)"></el-button>
          <el-button type="success" icon="el-icon-bottom" size="mini" title="商品下架" v-else @click="offSale(row)"></el-button>
          <el-button type="primary" icon="el-icon-edit" size="mini" title="" @click="$message({message:'正在开发中...',type:'warning'})"></el-button>
          <el-button type="info" icon="el-icon-info" size="mini" title="" @click="getSkuInfo(row)"></el-button>
          <el-popconfirm title="这是一段内容确定删除吗？" @onConfirm="deleteSku(row)" style="margin:10px">
            <el-button type="danger" icon="el-icon-delete" size="mini" title="删除spu" slot="reference"></el-button>
          </el-popconfirm>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页器-->
    <el-pagination
      align="center"
      :current-page="currentPage"
      :page-sizes="[3, 5, 8]"
      :page-size="size"
      layout=" prev, pager, next, jumper, ->, sizes,total, slot"
      :total="total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange">
    </el-pagination>
    <!--抽屉，右往左开  -->
    <el-drawer :visible.sync="showDrawer"
               :with-header="true"
               :show-close="false"
               size="40%"
    >
      <el-row>
        <el-col :span="5">名称</el-col>
        <el-col :span="16">{{skuInfo.skuName}}</el-col>
      </el-row>
      <el-row>
        <el-col :span="5">描述</el-col>
        <el-col :span="16">{{skuInfo.skuDesc}}</el-col>
      </el-row>
      <el-row>
        <el-col :span="5">价格</el-col>
        <el-col :span="16">{{skuInfo.price}}</el-col>
      </el-row>
      <el-row>
        <el-col :span="5">平台属性</el-col>
        <el-col :span="16">
          <el-tag type="success" v-for="(attr,index) in skuInfo.skuAttrValueList" :key="attr.id" style="margin:0 10px">{{attr.attrName}}</el-tag>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="5">图片</el-col>
        <el-col :span="16">
          <el-carousel height="500px">
            <el-carousel-item v-for="(item) in skuInfo.skuImageList" :key="item.id">
              <img :src="item.imgUrl" style="display:block;margin:auto;width:100%">
            </el-carousel-item>
          </el-carousel>
        </el-col>
      </el-row>
    </el-drawer>
  </div>
</template>

<script>
export default {
  name: 'Sku',
  data () {
    return{
      //分区器参数
      pages: 1,//总页数
      size: 3,//页面数据条数
      // records: [],//传递给pagination组件的数据
      currentPage: 1,//当前页
      total: 10,//数据总条数

      //skuList
      skuList:[],
      //摸一个sku的信息，byId
      skuInfo:[],

      //抽屉组件展示控制参数
      showDrawer:false,
    }
  },
  mounted (){
    this.getSkuList();
  },
  methods:{
    //获取sku数据
    async getSkuList(){
      const result = await this.$API.default.sku.reqSkuList(this.currentPage,this.size)
      // console.log(result)
      if(result.code==200){
        this.skuList=result.data.records;
      }
    },
    //查看其他页
    handleCurrentChange(page) {
      this.currentPage = page;
      this.getSkuList();
    },
    //修改每页展示数据size
    handleSizeChange(size) {
      this.size = size;
      this.getSkuList();
    },
    //上架按钮的回调
    async onSale(row){
      const result = await this.$API.default.sku.reqSkuOnSale(row.id)
      // console.log(result)
      if(result.code==200){
        this.$message({
          type:'success',
          message:"上架成功"
        })
        row.isSale=1;
      }
    },
    //下架按钮的回调
    async offSale(row){
      const result = await this.$API.default.sku.reqSkuOffSale(row.id)
      // console.log(result)
      if(result.code==200){
        this.$message({
          type:'warning',
          message:"下架成功"
        })
        row.isSale=0;
      }
    },
    //查看详情按钮的回调
    async getSkuInfo(row){
      //发请求
      const result =await this.$API.default.sku.reqSkuInfo(row.id);
      // console.log(result);
      if(result.code==200){
        this.showDrawer=true;
        this.skuInfo=result.data;
      }
    },
  }
}
</script>

<style>
.el-carousel__item:nth-child(2n) {
  background-color: #99a9bf;
}

.el-carousel__item:nth-child(2n+1) {
  background-color: #d3dce6;
}
.el-carousel__button{
  height: 10px;
  width:10px;
  background: #29d;
  border-radius:50%;
}
</style>
<style scoped>
    .el-row .el-col-5{
      font-size:18px;
      text-align:right;
    }
    .el-col{
      margin:10px 10px;
    }
</style>
